package com.weimob.mcloud.wechatwork.customer.mq.handler.losemsg;

import com.weimob.mcloud.wechatwork.core.base.SingleRequest;
import com.weimob.mcloud.wechatwork.core.base.SingleResponse;
import com.weimob.mcloud.wechatwork.core.entity.privatesphere.PrivateSphere;
import com.weimob.mcloud.wechatwork.core.entity.relation.speechcraft.SpeechCraft;
import com.weimob.mcloud.wechatwork.core.service.speechcraft.SpeechCraftService;
import com.weimob.mcloud.wechatwork.customer.domain.CustomerTouchInfo;
import com.weimob.soa.common.response.SoaResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 话术库
 * Create Time: 2022年05月23日 10:13
 *
 * @author maosheng.li
 **/
@Service
@Slf4j
public class SpeechCraftTouchImpl implements CustomerTouchService {

    @Resource
    private SpeechCraftService speechCraftService;
    @Override
    public CustomerTouchInfo getCustomerTouchInfo(PrivateSphere privateSphere, CustomerTouchInfo touchInfoRequest) {
        CustomerTouchInfo result = new CustomerTouchInfo();
        result.setTaskId(touchInfoRequest.getTaskId());
        SpeechCraft speechCraft = new SpeechCraft();
        speechCraft.setId(touchInfoRequest.getTaskId());
        SingleRequest<SpeechCraft> speechCraftSingleRequest = new SingleRequest();
        speechCraftSingleRequest.setData(speechCraft);
        speechCraftSingleRequest.setPrivateSphere(privateSphere);
        SoaResponse<SingleResponse<SpeechCraft>, ?> multiResponseSoaResponse =
                speechCraftService.querySpeechCraftDetail(speechCraftSingleRequest);
        SingleResponse<SpeechCraft> responseVo = multiResponseSoaResponse.getResponseVo();
        if(responseVo != null && responseVo.getData() != null){
            SpeechCraft speechCraftResult = responseVo.getData();
            result.setTaskName(speechCraftResult.getTitle());
        }
        return result;
    }
}
